<template>
  <div>
    <div class="slot">
      <div class="top">
        <div class="return" @click="goback">
          <img src="@/assets/my/zuo.png" alt />
        </div>
        <span>我的地址</span>
      </div>
    </div>
    <div class="main">
      <div class="main_center">
        <div class="center_li" @click="huoquid(item.id)" v-for="item in addresslist" :key="item.id">
          <div class="li_left">
            <div class="left_top">
              <div class="username">{{item.name}}</div>
              <div class="usernumb">{{item.phone}}</div>
              <div class="morenbtn" v-show="item.is_default===1">默认地址</div>
            </div>
            <div class="left_info">{{item.province}}{{item.city}}{{item.area}}{{item.detail}}</div>
          </div>
          <div class="li_right" @click.stop="changeaddress(item.id)">
            <img src="@/assets/pblic/bianji.png" alt />
          </div>
        </div>
      </div>
    </div>
    <div class="btn1">
      <div class="newaddress" @click="gonewaddress">新增地址</div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import bus from "@/utils/bus";
export default {
  data() {
    return {
      addresslist: [],
      orderid: 0,
      type: 0,
      token:"",
      cart_ids:'',
    };
  },
  methods: {
    goback() {
      this.$router.back()
      // if (this.type) {
      //    this.$router.push({
      //     path: "/confirmorder",
      //     query: { order_id: this.orderid, type: this.type , cart_ids: this.cart_ids},
      //   });
      // } else {
      //   this.$router.push({
      //     path: "/my",
      //   });
      // }
    },
    // 添加地址
    gonewaddress() {
      this.$router.push({
        path: "/addressadd",
        query: { type: this.type, order_id: this.orderid , cart_ids: this.cart_ids},
      });
    },
    // 修改地址
    changeaddress(id) {
      // this.$router.push("/address");
      this.$router.push({
        path: "/address",
        query: { id, type: this.type, order_id: this.orderid , cart_ids: this.cart_ids},
      });
    },
    huoquid(addressid) {
      if (this.orderid) {
        this.$router.replace({
          path: "/confirmorder",
          query: { addressid, order_id: this.orderid, type: this.type , cart_ids: this.cart_ids},
        });
      }
    },
  },
  mounted() {
    this.token = window.localStorage.getItem("token")
    axios.post("/index/user/ads_list", this.$qs.stringify({ token: this.token })).then((res) => {
      console.log(res.data);
      if (res.data.code === 1) {
        this.addresslist = res.data.data;
      } else {
        this.$toast(res.data.msg);
      }
    });

    this.type = this.$route.query.type;
    this.orderid = this.$route.query.order_id;
    this.cart_ids = this.$route.query.cart_ids;
  },
};
</script>

<style lang="scss" scoped>
.slot {
  width: 100%;
  height: 44px;
  .top {
    width: 100%;
    height: 44px;
    display: flex;display: -webkit-flex;
    justify-content: center;
    align-items: center;
    background: white;
    position: fixed;
    top: 0;
    left: 0;
    .return {
      width: 38px;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      display: flex;display: -webkit-flex;
      justify-content: center;
      align-items: center;
      img {
        width: 8px;
        height: 15px;
      }
    }
    span {
      font-size: 18px;
      font-family: PingFang SC;
      font-weight: bold;
      color: #000000;
      line-height: 44px;
    }
  }
}
.main {
  width: 100%;
  border-top: 8px solid #f8f8f8;
  .main_center {
    width: 345px;
    margin: auto;
    .center_li {
      width: 100%;
      display: flex;display: -webkit-flex;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #f8f8f8;
      padding-bottom: 15px;
      .li_left {
        width: 285px;
        .left_top {
          display: flex;display: -webkit-flex;
          align-items: center;
          margin-top: 18px;
          .username {
            font-size: 15px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #000000;
            line-height: 15px;
          }
          .usernumb {
            font-size: 12px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #888888;
            line-height: 12px;
            margin-left: 8px;
          }
          .morenbtn {
            width: 48px;
            height: 15px;
            background: #4c78fa;
            border-radius: 3px;
            font-size: 11px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #ffffff;
            line-height: 15px;
            text-align: center;
            margin-left: 8px;
          }
        }
        .left_info {
          font-size: 12px;
          font-family: PingFang SC;
          font-weight: 500;
          color: #444444;
          line-height: 15px;
          margin-top: 12px;
        }
      }
      .li_right {
        width: 16px;
        height: 16px;
        margin: 5px 0 5px 5px;
        img {
          width: 100%;
        }
      }
    }
  }
}
.btn1 {
  width: 100%;
  height: 64px;
  background: #ffffff;
  box-shadow: 0px -1px 0px 0px rgba(0, 0, 0, 0.1);
  display: flex;display: -webkit-flex;
  justify-content: center;
  align-items: center;
  position: fixed;
  left: 0;
  bottom: 0;
  .newaddress {
    width: 200px;
    height: 44px;
    background: #fdd40a;
    border-radius: 22px;
    font-size: 15px;
    font-family: PingFang SC;
    font-weight: bold;
    color: #222222;
    line-height: 44px;
    text-align: center;
  }
}
</style>